package MyThread;

public class Long {

    public static int GetLongIndex(int n, int[] satis, int k) {
        if(k > n){
            return -1;
        }
        int tmp =0;
        for(int i=0; i<k; i++){
            tmp += satis[i];
        }
        int max_index = k / 2; // 最大的位置
        int maxx = tmp; // 最大的数
        for(int i=k; i<n; i++){
            tmp -= satis[i-k]; //先减后加
            tmp += satis[i];
            if(tmp > maxx){
                maxx = tmp;
                max_index = (i+1 + i+1-k+1)/2;
            }
        }
        return max_index;
    }

    public static void main(String[] args) {
        int n = 10, k=3;
        int[] satic = new int[]{5,5,5,10,10,10,5,10,10,10};
        System.out.println(GetLongIndex(n, satic, k));
    }
}
